<?php
class Admin_Form_SectorAdd extends Zend_Dojo_Form {
	
	public function init() {
		$this->setName("SectorAdd");
		$this->setMethod('post');
		$this->setOptions(array (
			'onSubmit' => "return(validateForm(this))"
		));

		$id = new Zend_Form_Element_Hidden('id');
		$id->addFilter('Int');

		$this->addElement('ValidationTextBox', 'name', array (
			'label' => 'Nome: ',
			'focus' => true,
			'required' => true,
			'invalidMessage' => 'Nome inválido',
			'style' => 'width: 400px;',
			
		));

		$this->addElement('ValidationTextBox', 'acronym', array (
			'label' => 'Sigla: ',
			'focus' => true,
			'required' => true,
			'maxlength' => 202,
			'regExp' => '[\w]+',
			'invalidMessage' => 'Sigla inválida',
			'style' => 'width: 250px;',
			
		));

		//Organs
		$ogansDbTable = new Admin_Model_Organs();
		$organs = $ogansDbTable->getOrgans();
		$organOptions[null] = '';
		foreach ($organs as $key => $val) {
			$organOptions[$val['id']] = $val['name'];
		}

		$this->addElement('ComboBox', 'id_organ', array (
			'label' => 'Orgão: ',
			'value' => 'id_organ',
			'style' => 'width: 400px;',
			'required' => true,
			'autocomplete' => true,
			'multiOptions' => $organOptions
		));

		//Sectors
		$sectorDbTable = new Admin_Model_Sectors();
		$sectors = $sectorDbTable->getSectors();
		$sectorOptions[null] = '';
		foreach ($sectors as $key => $val) {
			$organsDbTable = new Admin_Model_Organs();
			$organ = $organsDbTable->getOrganById($val['id_organ']);
			$sectorOptions[$val['id']] = $organ['acronym'].'-'.$val['name'];
		}

		$form = $this->addElement('ComboBox', 'id_sector', array (
			'label' => 'Setor Vinculado: ',
			'value' => 'id_sector',
			'style' => 'width: 400px;',
			'required' => false,
			'autocomplete' => true,
			'multiOptions' => $sectorOptions
		));

		$this->addDisplayGroup(array (
			'name',
			'acronym',
			'id_organ',
			'id_sector'
		), 'basicos', array (
			'legend' => "Dados básicos"
		));

		//----------------------------------------------------------------------------------

		$this->addElement('SubmitButton', 'insert', array (
			'label' => 'Salvar',
			'required' => true,
			'ignore' => false,
			
		));

	}
}